package com.hxexp.weixin.test;

import org.junit.Assert;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;

import com.hxexp.weixin.common.cache.TokenCacheManager;
import com.hxexp.weixin.hpe.api.login.model.LoginResultBean;
import com.hxexp.weixin.test.runner.JUnit4WithSpringLogClassRunner;

/**
 * token缓存服务实现类测试
 *
 * @author wang.bin
 *
 */
@RunWith(JUnit4WithSpringLogClassRunner.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@ContextConfiguration(locations = { "classpath:conf/spring/spring-biz.xml", "classpath:conf/spring/spring-ehcache.xml" })
public class TokenCacheManagerTester {

    @Autowired
    private TokenCacheManager tokenCacheManager;

    private static String token = "1";
    private static LoginResultBean loginResultBean = new LoginResultBean();

    @Test
    public void testCase01() {
        loginResultBean.setUserId("1");
        loginResultBean.setUsername("kk");
        loginResultBean.setEmail("kk@qq.com");
        tokenCacheManager.saveUserToCache(token, loginResultBean);
    }

    @Test
    public void testCase02() {
        LoginResultBean returnValue = tokenCacheManager.getUserFromCache(token);
        Assert.assertEquals(loginResultBean, returnValue);
    }
}
